package GUI;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;
import javax.swing.JButton;
import javax.swing.JPanel;



/**
 * This class creates a preview window of selected elements in the list or
 * of SceneElements which gains the focus in the editing window
 * @author Wayang Group Bremen
 * @version 0.9
 */

public class ActiveFigurePanelGui extends JPanel{

	private static final long serialVersionUID = 1L;
	public String path;
	public JButton active;
	public BufferedImage image;
	public boolean resetPanel = false;
	public ButtonStateGui buttonState;

	/**
	 * Constructor
	 * @param buttonState the modifier buttons for the SceneElement
	 */
	
	public ActiveFigurePanelGui(ButtonStateGui buttonState){
		this.buttonState = buttonState;
	}



	/**
	 * This method is called when an icon in the character selection List
	 * is selected or when an SceneElement gains the focus in the editing window.
	 * An image will be created with the path, which will be drawn after repaint 
	 * is called.
	 */
	public void showActiveFigure(String path){
		this.path = path;

		try {
			image = ImageIO.read(new File(path));
		} catch (IOException e) {
			e.printStackTrace();
		}
		repaint();
	}

	/**
	 * This method will be called when there is a tab change in the 
	 * characterselection list, or when the active Movie is changing.
	 */
	
	public void clearPanel() {
		resetPanel = true;
		repaint();
	}

	/**
	 * Paints a preview of the selected figure, when reset panel is false.
	 * Otherwise the preview panel will be cleared.
	 */
	
	public void paintComponent(Graphics g) {
		super.paintComponent(g);
		if(!resetPanel) {
			g.drawImage(image, 9, 9, this);
		}
		else {
			//g.setColor(Color.white);
			g.setColor(new Color(0,0,0,0));
			g.fillRect(0, 0, super.getWidth(), super.getHeight());
			resetPanel = false;
		}
	}
}
